board = [
     ["A","B","C","E"]
    ,["S","F","C","S"]
    ,["A","D","E","E"]
], 
word = "ABCCED"

var exist = function(board, word) {
    //终止条件
    if(board.length === 0){
        return false
    }
    if(word.length === 0){
        return true
    }
    //开始循环找
    let row = board.length
    let col = board[0].length
    for(let i=0;i<row;i++){
        for(let j=0;j<col;j++){
            //每一个字母都可以做为起点搜索
            const ret = find(i,j,0)  //0就是当前要查找的元素的下标
            if(ret){
                return ret
            }
        }
    }
    return false
    //递归函数 
    function find(i,j,cur){
        if(i >= row || i < 0){
            return false 
        }
        if(j >= col || j < 0){
            return false 
        }

        let letter = board[i][j]
        //判断循环结束
        if( letter !== word[cur] ){//找到的不是指定字母  直接跳出循环 只有找到的字母是匹配的字母代码才会继续向下走
            return false
        }
        if( cur === word.length - 1 ){//找到最后一个了
            return true
        }
        board[i][j] = null //选择当前字母
        //进行下一步  有一个找到就算
        const  ret =    find(i+1,j,cur+1) ||
                        find(i-1,j,cur+1) ||
                        find(i,j+1,cur+1) ||
                        find(i,j-1,cur+1) 
        board[i][j] = letter //回撤
        return ret
    }
    
};

exist(board,word)